﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Text;
using System.Collections.Generic;
using System.Data.SqlClient;
using FileConvertPdfSystemSQLHelper;
using FileConvertPdfSystemModel;

namespace FileConvertPdfSystemDAL
{
    public class File_Share1
    {
        public int Add_File_Share(File_share fileshare)
        {
            FileConvertPdfSystemSQLHelper.SQLHelper sqlHelper = new FileConvertPdfSystemSQLHelper.SQLHelper();
            SqlParameter[] ParamList ={ 
                 sqlHelper.CreateInParam("@File_ID",SqlDbType.Int,4, fileshare.File_ID),
                 sqlHelper.CreateInParam("@File_Name",SqlDbType.NVarChar,50,fileshare._File_Name),
                 sqlHelper.CreateInParam("@File_UploadTime",SqlDbType.DateTime,8,fileshare._File_UploadTime)
                                      };
            try
            {
                return (sqlHelper.RunProc("Add_File_Share", ParamList));
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }


        }
        public void Update_File_Share(File_share fileshare)
        {
            FileConvertPdfSystemSQLHelper.SQLHelper sqlHelper = new FileConvertPdfSystemSQLHelper.SQLHelper();
            SqlParameter[] ParamList ={ 
                 sqlHelper.CreateInParam("@ID",SqlDbType.Int,4,fileshare.ID),
                 sqlHelper.CreateInParam("@File_ID",SqlDbType.Int,4, fileshare.File_ID),
                 sqlHelper.CreateInParam("@File_Name",SqlDbType.NVarChar,50,fileshare._File_Name),
                 sqlHelper.CreateInParam("@File_UploadTime",SqlDbType.DateTime,8,fileshare._File_UploadTime)
                                      };
            try
            {
                sqlHelper.RunProc("Update_File_Share", ParamList);
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }

        }

        public void Delete_File_Share(int nID)
        {
            FileConvertPdfSystemSQLHelper.SQLHelper sqlHelper = new FileConvertPdfSystemSQLHelper.SQLHelper();
            SqlParameter[] ParamList = { sqlHelper.CreateInParam("@ID", SqlDbType.Int, 4, nID) };
            try
            {
                sqlHelper.RunProc("Delete_File_Share", ParamList);
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }

        }
        public List<File_share> Get_File_Share()
        {
            FileConvertPdfSystemSQLHelper.SQLHelper sqlHelper = new FileConvertPdfSystemSQLHelper.SQLHelper();
            SqlDataReader rec = null;
            try
            {
                sqlHelper.RunProc("Get_File_Share", out rec);
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }
            List<File_share> fileshare = new List<File_share>();
            while (rec.Read())
            {
                File_share fileshare1 = new File_share();
                fileshare1.ID = Int32.Parse(rec["ID"].ToString());
                fileshare1.File_ID = Int32.Parse(rec["File_ID"].ToString());
                fileshare1._File_Name = rec["File_Name"].ToString();
                fileshare1._File_UploadTime = DateTime.Parse(rec["File_UploadTime"].ToString());
                fileshare.Add(fileshare1);
                fileshare1 = null;
            }
            return fileshare;
        }

        public DataSet Get_File()
        {
            FileConvertPdfSystemSQLHelper.SQLHelper sqlHelper = new FileConvertPdfSystemSQLHelper.SQLHelper();
            string str = "select ID,File_ID,File_Name,File_UploadTime from File_Share ORDER BY ID DESC";
            DataSet ds = null;
            try
            {
                sqlHelper.RunSQL(str, ref ds);
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }
            return ds;
        }
    }
}
